package admin.sugangadmin.dao;

import java.util.List;

import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Component;

import com.sugangadmin.domain.SugangAdminCommand;

@Component
public class SugangAdminDaoImpl extends SqlSessionDaoSupport implements SugangAdminDao{

	@Override
	public void insertSugangAdmin(SugangAdminCommand sugangAdminCommand) {
		getSqlSession().insert("insertSugangAdmin",sugangAdminCommand);		
	}

	@Override
	public List<SugangAdminCommand> getSugangAdminList(String gwa_code) {
		List<SugangAdminCommand> list = getSqlSession().selectList("getSugangAdminList",gwa_code);
		return list;
	}

	@Override
	public void deleteSugangAdmin(List<String> seqList) {
		SqlSessionFactory sqlSessionFactory = 
				new SqlSessionFactoryBuilder().build(getSqlSession().getConfiguration());
		SqlSession session = sqlSessionFactory.openSession(ExecutorType.BATCH);

		try
		{
			for(String seq:seqList)
			{
				session.delete("deleteSugang",seq);	
			}
			session.commit();
		}catch(Exception e)
		{
			e.printStackTrace();
			session.rollback();
		}finally
		{
			session.close();
		}
	}

	@Override
	public void updateSugangAdmin(SugangAdminCommand sugangAdminCommand) {
		getSqlSession().update("updateSugangAdmin",sugangAdminCommand);
		
	}

}
